package cn.my.quickSort;

import java.util.Arrays;

public class QuickSort3 {
	public static void sort(int[] a, int low, int high){
		if (low > high) return;
		int i = low;     
		int j = high;
		int index = a[i];
		while (i < j){
			while (i<j && a[j]>=index) j--;
			if (i < j) a[i++] = a[j];
			while (i<j && a[i]<index) i++;
			if (i < j) a[j--] = a[i];
		}
		a[i] = index;
		sort(a, low, i-1);
		sort(a,i+1, high);
	}
	
	public void quickSort(int[] a){	
		sort(a, 0, a.length-1);
	}
	public static void main(String[] args) {
		QuickSort3 qs = new QuickSort3();
		int a[] = {49, 79, 56, 38, 40, 84};
		qs.quickSort(a);
		System.out.println(Arrays.toString(a));
	}
}
